/**
 * Moondance UML modeling tool
 * 
 * This program is free software; you can redistribute it and
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package ro.pub.cs.se.moondance.model;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.graphics.Image;

public class UMLPackage extends UMLEntity {
	private static final long serialVersionUID = -5628366512286905180L;
	private String name;
	private ArrayList<UMLBaseClass> containedClasses = new ArrayList<UMLBaseClass>();
	private ArrayList<UMLPackage> containedPackages = new ArrayList<UMLPackage>();
	private ModelElement parent; // UMLDiagram or UMLPackage

	private int classIndex = 0;
	private int interfaceIndex = 0;
	private int packageIndex = 0;

	private static final Image PACKAGE_ICON = createImage("icons/class_types/package_small.gif");

	public UMLPackage() {
		super();
	}

	public UMLPackage(String name, UMLEntity parent) {
		super();
		this.name = name;
		this.parent = parent;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setParent(ModelElement parent) {
		this.parent = parent;
	}

	public boolean addClass(UMLBaseClass newClass) {
		if (!containedClasses.contains(newClass)) {
			containedClasses.add(newClass);
			firePropertyChange(CHILD, null, newClass);
			return true;
		}
		return false;
	}

	public boolean addPackage(UMLPackage newPackage) {
		if (!containedPackages.contains(newPackage)) {
			containedPackages.add(newPackage);
			firePropertyChange(CHILD, null, newPackage);
			return true;
		}
		return false;
	}

	public boolean removeClass(UMLBaseClass newClass) {
		if (containedClasses.remove(newClass)) {
			firePropertyChange(CHILD, newClass, null);
			return true;
		}
		return false;
	}

	public boolean removePackage(UMLPackage newPackage) {
		if (containedPackages.remove(newPackage)) {
			firePropertyChange(CHILD, newPackage, null);
			return true;
		}
		return false;
	}

	public String getName() {
		return name;
	}

	public ModelElement getParent() {
		return parent;
	}

	public List<UMLBaseClass> getContainedClasses() {
		return containedClasses;
	}

	public List<UMLPackage> getContainedPackages() {
		return containedPackages;
	}

	public String toString() {
		return name;
	}

	public Image getIcon() {
		return PACKAGE_ICON;
	}

	public String getLabelText() {
		String labelText = name;
		return labelText;
	}

	public int getNewClassIndex() {
		classIndex++;
		return classIndex;
	}

	public int getNewInterfaceIndex() {
		interfaceIndex++;
		return interfaceIndex;
	}

	public int getNewPackageIndex() {
		packageIndex++;
		return packageIndex;
	}

}